#include "FileSystem.h"
#include <filesystem>
#include <fstream>
#include <iostream>

using namespace std;
namespace fs = std::filesystem;

void getCurrentPath()
{
    cout << "Current path is " << fs::current_path() << endl;
}

void getFileSize()
{
    fs::path p = fs::current_path() / "example.bin";
    std::ofstream(p).put('a'); // create file of size 1
    std::cout << "File size = " << fs::file_size(p) << '\n';
    fs::remove(p);
}

void createDirectory()
{
    fs::create_directories("sandbox/1/2/a");
    fs::create_directory("sandbox/1/2/b");
    fs::permissions("sandbox/1/2/b", fs::perms::others_all, fs::perm_options::remove);
    fs::create_directory("sandbox/1/2/c", "sandbox/1/2/b");
    fs::remove_all("sandbox");
}

void copyFiles()
{
    fs::create_directories("sandbox/dir/subdir");
    std::ofstream("sandbox/file1.txt").put('a');
    fs::copy("sandbox/file1.txt", "sandbox/file2.txt"); // copy file
    fs::copy("sandbox/dir", "sandbox/dir2"); // copy directory (non-recursive)
    const auto copyOptions = fs::copy_options::update_existing
        | fs::copy_options::recursive
        | fs::copy_options::directories_only;
    fs::copy("sandbox", "sandbox_copy", copyOptions);
    fs::remove_all("sandbox");
    fs::remove_all("sandbox_copy");
}

void renameFile()
{
    fs::path p = fs::current_path() / "sandbox";
    fs::create_directories(p / "from");
    std::ofstream(p / "from/file1.txt").put('a');
    fs::create_directory(p / "to");
    fs::rename(p / "from/file1.txt", p / "to/file2.txt"); // OK
    fs::rename(p / "from", p / "to/subdir"); // OK
    fs::remove_all(p);
}
